package leecode

type NumArray struct {
	sums []int //前缀和数组
}

func Constructor303(nums []int) NumArray {
	sums := make([]int, len(nums)+1) //存放数组前缀和
	for index, num := range nums {
		sums[index+1] = sums[index] + num
	}
	return NumArray{sums: sums}
}

func (this *NumArray) SumRange(left int, right int) int {
	result := this.sums[right+1] - this.sums[left]
	return result
}
